/**
 * @author Salim
 *
 */


package Server;

import java.io.*;
import java.net.SocketException;

import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ObjectNotActive;
import org.omg.PortableServer.POAPackage.ServantAlreadyActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

public class StationServer extends Thread{
 
	String myServerName;
	int myPortNo = 0;
	
	public StationServer(String serverName, int portNo) {
		myServerName = serverName;
		myPortNo = portNo;
	//	System.out.println("myServerName: " + myServerName +  "       StationServer(int portNo) :" + portNo);
		
	//	Thread t = new Thread(new UDPServer(this.getStationServerName(),this.getPort(),StationServer, this));
	//	(new UDPServer(myServerName,myPortNo).start();//,spl)).start();
	} // end of StationServer parameterized constructor
	
	public int getPort()
	{
		return this.myPortNo;
	}
	
	public String getStationServerName()
	{
		return this.myServerName;
	}
	
	// MAIN block for StationServer begins here ...
	public static void main(String[] args) throws ServantAlreadyActive, WrongPolicy, ObjectNotActive, InvalidName, 
	FileNotFoundException, AdapterInactive, SocketException {
	
		StationServerImpl spvm = new StationServerImpl("SPVM",6789);
		StationServerImpl spl = new StationServerImpl("SPL",6790);
		StationServerImpl spb = new StationServerImpl("SPB",6791);
		
		spvm.setServerName(6789);
		spl.setServerName(6790);
		spb.setServerName(6791);
		
//		System.out.println(spvm.getServerName());
//		System.out.println(spl.getServerName());
//		System.out.println(spb.getServerName());
		
	//	StationServer ss_spvm = new StationServer("spvm", StationServerImpl.ports[0]);
	//	StationServer ss_spl = new StationServer("spl", StationServerImpl.ports[1]);
	//	StationServer ss_spb = new StationServer("spb", StationServerImpl.ports[2]);
	
				
				//starting the threads for UDP connection
		/*
		Thread t = new Thread(new UDPServer("SPVM",StationServerImpl.ports[0],ss_spvm, spvm));
		t.start();
				
		Thread t2= new Thread(new UDPServer("SPL",StationServerImpl.ports[1],ss_spl,spl));
		t2.start();
		
		Thread t3= new Thread(new UDPServer("SPB",StationServerImpl.ports[2],ss_spb,spb));
		t3.start();*/
		
		System.out.println(StationServerImpl.ports[0]);
		System.out.println(StationServerImpl.ports[1]);
		System.out.println(StationServerImpl.ports[2]);
		
			  	(new UDPServer("SPVM",StationServerImpl.ports[0],spvm)).start();
				(new UDPServer("SPL",StationServerImpl.ports[1],spl)).start();
				(new UDPServer("SPB",StationServerImpl.ports[2],spb)).start();
				
				
				System.out.println("Montreal Server - SPVM ready and waiting ...");
				System.out.println("Longueuil Server - SPL ready and waiting ...");  
				System.out.println("Brossard Server - SPB ready and waiting ...");  
				
				
		
	}

}
